clear
%% PROBLEM
d = 2;
x_bound = repmat([-6,6],[d,1]);
OptSet.sol = [3,2;
    -2.805118,3.131312;
    -3.779310,-3.283186;
    3.584428,-1.848126];
OptSet.fval = 0;
OptSet.radius = 0.1;
precision_init = 0.4; % 3.848
MaximalBudget = 50000;
precision = [0.074, 0.024, 0.0074, 0.0024];

rep = 1;

Problem.Dimension = d; % the dimension of the decision variable
Problem.LowerBound = x_bound(:,1)'; % the lower bound of the decision variable
Problem.UpperBound = x_bound(:,2)'; % the upper bound of the decision variable
Problem.ObjFunc = @(x)(-ObjValue(x));  % the objective function
%% ALGORITHM
Algorithm.AntSize = 100;  % the size of the ant
Algorithm.NichSizeSet = 2:20;
Algorithm.std_ls = 1E-4;
Algorithm.N_ls = 2;
Algorithm.MaxFEs = 5000;%MaximalBudget; % the maximal budget

tic
[ant, EvaluationNum, GenerationNum] = lamsaco(Problem, Algorithm);
toc
GenerationNum
EvaluationNum

%% FIGURES
if rep == 1
    if d==1
        x=x_bound(1,1):(x_bound(1,2)-x_bound(1,1))/1000:x_bound(1,2);
        z=ObjValue(x');
        z_max=max(z);
        z_min=min(z);
        figure()
        hold on
        plot(x,z)
        plot(ant(:,2),ant(:,1),'.')
        hold off
    end
    if d == 2
        figure()
        hold on
        scatter(ant(:,2),ant(:,3),2,ant(:,1),'filled');
        plot(OptSet.sol(:,1),OptSet.sol(:,2),'o')
        hold off
        xlabel('','Interpreter','latex','String','$x_1$')
        ylabel('','Interpreter','latex','String','$x_2$')
        set(gca,'Fontname','Times New Roman','FontSize',16);
    end
end
